'use strict'
import axios from 'axios'
import qs from 'qs'

const service = axios.create({
    timeout: 5000,
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
    }
})
service.interceptors.request.use((config) => {
    config.headers['Content-Type'] = 'application/x-www-form-urlencoded'
    if (config.method === 'post') {
        let userJsonStr = sessionStorage.getItem('user')
        if (userJsonStr) {
            let userEntity = JSON.parse(userJsonStr)
            config.data.id = userEntity.id
        }
        config.data = qs.stringify(config.data)
    }
    return config
  },
  (error) => {
    return Promise.reject(error)
})

export default service
